package org.dromara.utils.utils;

import org.dromara.Nyt7PolicyInsurance.domain.Nyt7PolicyInsurance;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

public class SubUtil {

    public static BigDecimal getAllSub(List<Nyt7PolicyInsurance> nyt7PolicyInsurances){

        // 计算总金额
        BigDecimal totalCentralFiscalSubsidy = nyt7PolicyInsurances.stream()
            .map(Nyt7PolicyInsurance::getTotalCentralFiscalSubsidy)
            .reduce(BigDecimal.ZERO, BigDecimal::add);

        BigDecimal totalProvincialFiscalSubsidy = nyt7PolicyInsurances.stream()
            .map(Nyt7PolicyInsurance::getTotalProvincialFiscalSubsidy)
            .reduce(BigDecimal.ZERO, BigDecimal::add);

        BigDecimal totalMunicipalFiscalSubsidy = nyt7PolicyInsurances.stream()
            .map(Nyt7PolicyInsurance::getTotalMunicipalFiscalSubsidy)
            .reduce(BigDecimal.ZERO, BigDecimal::add);

        BigDecimal totalDistrictAndCountyFiscalSubsidy = nyt7PolicyInsurances.stream()
            .map(Nyt7PolicyInsurance::getTotalDistrictAndCountyFiscalSubsidy)
            .reduce(BigDecimal.ZERO, BigDecimal::add);

        BigDecimal totalOtherFiscalSubsidies = nyt7PolicyInsurances.stream()
            .map(Nyt7PolicyInsurance::getTotalOtherFiscalSubsidies)
            .reduce(BigDecimal.ZERO, BigDecimal::add);

        // 计算所有补贴的总和
        return totalCentralFiscalSubsidy
            .add(totalProvincialFiscalSubsidy)
            .add(totalMunicipalFiscalSubsidy)
            .add(totalDistrictAndCountyFiscalSubsidy)
            .add(totalOtherFiscalSubsidies);
    }
}
